import React from 'react';
import Grid from '../../components/table/grid';
import { injectIntl } from 'react-intl';
import moment from 'moment';
import {Form ,Row ,Col, Select ,Button,Input,Divider,Modal} from 'antd';
import axios from 'axios';
import qs from 'qs';
import { sessionManager } from '../../utils/sessionStorage';
const FormItem = Form.Item;
const createForm = Form.create;
const Option = Select.Option;
const confirm = Modal.confirm;
const settleTypes = [
	'正常分账',
	'折扣分账',
	'SAAS分账'
]
class ledgerMonthOrderList extends React.Component {
	constructor(props) {
		super(props);
		this.columns = [
			{
				title: '订单号',
				width: 100,
				key: 'orderId',
				dataIndex:'orderId',
			},
			{
				title: '负责人',
				width: 100,
				key: 'chiefName',
				dataIndex:'chiefName',
			},
			{
				title: '分账账号',
        width: 150,
        dataIndex: 'account',
				key: 'account',
			},
			{
				title: '桩群名称',
        width: 150,
        dataIndex: 'groupName',
				key: 'groupName',
			},
			{
				title: '订单时间',
        width: 150,
        dataIndex: 'splitTime',
				key: 'splitTime',
			},
			{
				title: '电量(KWH)',
				width: 150,
				dataIndex: 'electric',
				key: 'electric',
			},
			{
				title: '电费(元)',
        width: 150,
        dataIndex: 'electricAmount',
				key: 'electricAmount',
			},
			{
				title: '服务费(元)',
        width: 150,
        dataIndex: 'serviceAmount',
				key: 'serviceAmount',
			},
			{
				title: '总费用(元)',
        width: 150,
        dataIndex: 'totalAmount',
        key: 'totalAmount',
			},
			{
				title: '分账来源',
				width: 150,
				dataIndex: 'settleType',
				key: 'settleType',
				render: (text) => {
					return <span>{settleTypes[text]}</span>
				}
			}
		];
		this.state = {
			refresh:0,
			params:{
			}
		};

  }
	componentWillMount(){
		this.setState({
			params:{
        settlementDay:sessionManager.get('settlementDate'),
        userId: JSON.parse(sessionManager.get('monthDetailParams')).userId
			}
		})
	}
	inquireBillList=(e)=>{
		e.preventDefault();
		this.props.form.validateFieldsAndScroll((errors, values) => {
			if (!!errors) {
				return;
			}
			console.info('Received values of form:',this.state.params,values);
			this.setState({
				params:Object.assign(this.state.params, values),
				refresh:this.state.refresh+1
			})
		});
	};
	exportAllLists(){
		console.log('导出列表')
	};
	freshGrid = () => {
		this.setState({
			refresh: this.state.refresh + 1
		});
	};

	goLink = (text, record, link) => {
		sessionManager.clearItem('rowRecord');
		this.props.history.push({pathname: `/finance/${link}`,state: {rowRecord: text}});
	};
	render() {
		const {getFieldDecorator} = this.props.form;
		const token=(JSON.parse(sessionStorage.getItem("token"))||{}).token;
		let exportQs=`${qs.stringify(this.state.params)}&token=${token}`;
		return (
			<div>
				<Form layout="inline" onSubmit={this.inquireBillList} className="pad-24">
					<FormItem label="分账来源">
						{getFieldDecorator('settleType', {
							initialValue: ''
						})(<Select style={{width: '200px'}}>
							<Option value={''} key={'settleType00'}>全部</Option>
              <Option value={0} key={'settleType000'}>正常分账</Option>
              <Option value={1} key={'settleType001'}>折扣分账</Option>
              <Option value={2} key={'settleType002'}>SAAS分账</Option>
						</Select>)}
					</FormItem>
					<FormItem>
						<Button type="primary" htmlType="submit" >查询</Button>
					</FormItem>
					<FormItem>
						<a href={`${axios.defaults.baseURL}/api/billSplit/billDetailList/export?${exportQs}`}>
							<Button type="primary" onClick={this.exportAllLists}>导出Excel</Button>
						</a>

					</FormItem>
				</Form>
				<Grid url="api/settlement/billSplit/billDetailList" columns={this.columns} refresh={this.state.refresh} params={this.state.params}/>
			</div>
		)
	}
}

ledgerMonthOrderList = createForm()(ledgerMonthOrderList);
export default injectIntl(ledgerMonthOrderList)